package com.assignwork.modules.pc.service.pc.impl;

import com.assignwork.dto.pcplan.PcShipEfficiencySubmitDto;
import com.assignwork.entity.pc.PcShipEfficiency;
import com.assignwork.mapper.PcShipEfficiencyMapper;
import com.assignwork.modules.pc.service.pc.IPcShipEfficiencyService;
import com.assignwork.vo.pc.PcShipEfficiencyVo;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
@DS("master_tjgsgs")
public class PcShipEfficiencyServiceImpl extends BaseServiceImpl<PcShipEfficiencyMapper, PcShipEfficiency> implements IPcShipEfficiencyService {
    @Override
    public boolean submitPcShipEfficiency(PcShipEfficiencySubmitDto submitDTO) {
        PcShipEfficiency copy = BeanUtil.copy(submitDTO, PcShipEfficiency.class);
        PcShipEfficiency one = lambdaQuery().eq(PcShipEfficiency::getBerth, submitDTO.getBerth()).one();

        if (Func.isNull(submitDTO.getId())) {
            if (Func.notNull(one)) {
                throw new RuntimeException("此泊位已存在");
            }
        } else {
            if (Func.notNull(one)) {
                if (!one.getId().equals(submitDTO.getId())) {
                    throw new RuntimeException("此泊位已存在");
                }
            }
        }
        return saveOrUpdate(copy);
    }

    @Override
    public List<PcShipEfficiencyVo> selectPcShipEfficiencyList() {
        List<PcShipEfficiencyVo> pcShipEfficiencyVos = baseMapper.selectPcShipEfficiencyList();
        return pcShipEfficiencyVos;
    }
}
